package com.yxj05;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;

public class ListDemo {
    public static void main(String[] args) {
        //创建集合对象
        ArrayList<String> array = new ArrayList<String>();
        array.add("hello");
        array.add("world");
        array.add("java");
        //遍历
        for(String s : array) {
            System.out.println(s);
        }
        System.out.println("----------");
        Iterator<String> it = array.iterator();
        while(it.hasNext()) {
            String s = it.next();
            System.out.println(s);
        }
        System.out.println("----------");

        for(int i = 0; i < array.size(); i++) {
            String s = array.get(i);
            System.out.println(s);
        }
        System.out.println("----------");

        LinkedList<String> linkedList = new LinkedList<String>();
        linkedList.add("1");
        linkedList.add("2");
        linkedList.add("3");
        for(String s : linkedList) {
            System.out.println(s);
        }
        System.out.println("+++++++");
        Iterator<String> itl = linkedList.iterator();
        while(itl.hasNext()) {
            String s = itl.next();
            System.out.println(s);
        }
        System.out.println("++++++++++");
        for(int i = 0; i < linkedList.size(); i++) {
            String s = linkedList.get(i);
            System.out.println(s);
        }
    }
}
